home *** CD-ROM | disk | FTP | other *** search
/ Aminet 15 / Aminet 15 - Nov 1996.iso / Aminet / dev / misc / BST_SystemDocs.lha / BeastV1 / Examples / BST_System / BST_Example2.txt < prev    next >
Encoding:
Text File  |  1996-03-22  |  3.9 KB  |  112 lines

  1.  
  2. Example2.c
  3. ==========
  4.  
  5. This example program creates the following object network;
  6.  
  7.  
  8.      OBM_INPUT  ,--------------, OBM_OUTPUT
  9.   ,------------>| math_ax2_obj |------------,
  10.   |        `--------------'            |
  11.   |                            | OBM_INPUT
  12.   |  OBM_INPUT  ,--------------, OBM_OUTPUT \    ,-------------, OBM_OUTPUT
  13.   |------------>| math_bx_obj  |--------------->| math_xy_obj |---,
  14.   |        `--------------'        /    `-------------'      |
  15.   |                        |              |
  16.   |  OBM_INPUT    ,--------------, OBM_OUTPUT |              |
  17.   |------------>| math_c_obj   |------------'              |
  18.   |        `--------------'                  |
  19.   |                                  |
  20.   `---------------------------------------------------------------'
  21.  
  22.  
  23. This network calculates the formula Y = A*X^2 + B*X + C. The calculation
  24. is done with long words, this could also be FFP (32-bits floats), but this
  25. would require some casts which would make the example _more_ unreadable ;-)
  26.  
  27.  
  28. How it works
  29. ------------
  30.  
  31. Let's start at the main() procedure.
  32.  
  33. * Four classes are defined;
  34.     MATH_ax2Class = "A * X^2" part.
  35.     MATH_bxClass  = "B * X" part.
  36.     MATH_cClass   = "C" part.
  37.     MATH_xyClass  = this class supplies the X value at the output, after
  38.             this it gathers the Y values at the input at add's
  39.             them.
  40.  
  41. * Every class get's four method's (OBM_INIT,OBM_INPUT,OBM_OUTPUT and OBM_SETATTR)
  42.             
  43. * New is the creation of the connections (OBJ_CreateConnection), with these
  44.   connections you can actually build your own program. You can connect any
  45.   method. So it is possible to connection the OBM_SETATTR method to the OBM_INIT
  46.   method of another object. Only, data along the connection is send by the
  47.   OBJ_ToOutput (or OBJ_FromInput) function. So the method must use this function
  48.   to make the connection work.
  49.   
  50. * The preset values of the classes are set (OBM_SETATTR).
  51.  
  52. * The calculation is started by triggering the OBM_OUTPUT method from the
  53.   math_xy_obj object.
  54.  
  55.  
  56. The classes
  57. -----------
  58.  
  59. MATH_ax2Class -
  60.  
  61.   mth_ax2_InputX - 
  62.     The class more or less 'waits' until it recieves data at the
  63.     OBM_INPUT method. Then it searches for the BTA_X tag. Please understand
  64.     that the TagList recieved is _read only_ because there is a chance, and
  65.     in this example it is the fact, that other object method will recieve this
  66.     TagList also.
  67.     The next thing to do is to construct a TagList with the result as BTA_Y
  68.     tag. This TagList is send with the OBJ_ToOutput function, it is send
  69.     to the object(s) connected to this object's OBM_OUTPUT method.
  70.  
  71.   mth_ax2_OutputX -
  72.       This method won't be called in this example at all!!!, the method
  73.       _would_ be called when an object connected to this object's OBM_OUTPUT
  74.       (math_xy_obj) would perform a OBJ_FromInput( .., OBM_INPUT,.. );
  75.       When this is done we must response with the result. But we do _not_
  76.       cache the A*X^2 result so we must ask for the X value. Thus a
  77.       OBJ_FromInput function again.
  78.     This demonstrate the 'two-way' connectivity of the BEAST connections.
  79.     In _normal_ case the forward connections (as used in this example)
  80.     should be enough. The backward connections could be used when the data
  81.     sizes are large.
  82.  
  83.   mth_ax2_SetAttr -
  84.       This is a largly overdone method function.... but it's an example, and
  85.       it shows how a 'normal' OBM_SETATTR should look like.
  86.       BTW: the OBM_GETATTR method should look very much the same, only that
  87.       the case statements are storing the result _into_ the TagList.
  88.     See also Methods.doc.
  89.     
  90. MATH_bxClass -
  91. MATH_cClass  -
  92.     All the same principle.
  93.     
  94. MATH_xyClass -
  95.  
  96.   mth_xy_InputY -
  97.       Every time a object has calculate a result this method is called.
  98.       It just looks for the BTA_Y tag, and if found adds it to the Y
  99.       instance.
  100.  
  101.   mth_xy_OutputX -
  102.       When called it reset the Y instance back to zero. Then constructs
  103.       the TagList with the preset X value. The OBJ_ToOutput function 
  104.       start the whole process.
  105.  
  106.  
  107. As you probably will notice is that all these methods have _a lot_ in
  108. common. And the BEAST is a OO-system so this all could be solved with
  109. Sub/Superclasses with the famous inheritance. Example3 shows this.
  110.  
  111.  
  112.